package com.group56;

import com.group56.mediator.AppCtrlrMediator;
import com.group56.utils.FXMLSrcMenu;
import com.group56.utils.FXMLViewHandler;
import javafx.application.Application;
import javafx.stage.Stage;

import static javafx.application.Platform.exit;

/**
 * 和MainApp是并列关系，GymApp通过更新Pane中的组件来管理整个app跳转
 */
public class GymApp extends Application {
    public static String customerId="1";
    public static Stage initStage = new Stage();//for login and register
    public static Stage mainStage = new Stage();//for customer-end and coach-end app
    @Override
    public void start(Stage stage) throws Exception {
        initStage = stage;
        //登陆验证
        FXMLViewHandler.putViewInStage(initStage, FXMLSrcMenu.UserEnd.LOG_IN.getSrc(), "login/register");
        initStage.show();
        //当登陆页面hide：
        initStage.setOnHidden(e->{
            if(TestApp.customerId!=null) {
                try {
                    new TestApp().start(mainStage);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }else if (CoachApp.coachId!=null){
                try {
                    new CoachApp().start(mainStage);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }else{exit();}
        });
    }
}
